package com.jiayi.weiphoto.util;


import com.jiayi.weiphoto.activity.MainActivity;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class ViewsUtil {
	public static final int ViewWidth = 0;
	public static final int ViewHeight = 1;
	
	public static DisplayMetrics getScreenDM(Activity activity){
		DisplayMetrics dm = new DisplayMetrics();
		activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
		return dm;
	}
	
	public static ImageView prepateImageView(ImageView imgView, Bitmap bitmap){
		float scale = 1;
		if(bitmap == null){
			return imgView;
		}
		if(MainActivity.screenWidth > bitmap.getWidth()){
			scale = (float) MainActivity.screenWidth / bitmap.getWidth() ;
		}else{
			scale = (float)MainActivity.screenWidth / bitmap.getWidth();
		}
		int width = MainActivity.screenWidth;
		int height =  (int) (bitmap.getHeight()*scale);
		imgView.setLayoutParams(new LinearLayout.LayoutParams(MainActivity.screenWidth, (int) (bitmap.getHeight()*scale)));
		return imgView;
	}
	
}
